package com.device.grant.dao.impl;

import java.util.Map;

import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.device.grant.dao.BaseDao;
import com.device.grant.dao.IDeviceGrantDao;
import com.device.grant.pojo.IDeviceGrant;

@Repository("IDeviceGrantDao")
public class IDeviceGrantDaoImpl extends BaseDao<IDeviceGrant> implements IDeviceGrantDao {

    private static final String TABLE = "IDeviceGrant";

    private static final String ID = "grantID";

    public boolean insertDeviceGrant(IDeviceGrant deviceGrant) {
        return super.insert(TABLE, ID, deviceGrant);
    }

    public IDeviceGrant queryDeviceInAppointment(Map<String, Object> map) {
        String sql = "select ie.empID,ie.empNo as userID, ie.cardNO, appoint.startTime as beginDate, appoint.endTime as limitDate, dev.deviceID from appointment appoint, iemployee ie, IDevice dev, Apparatus yiqi where  ie.empId = appoint.empId  and dev.deviceId = yiqi.deviceID and appoint.appcode = yiqi.appCode and appoint.id = ?";

        return simpleJdbcTemplate.queryForObject(sql, ParameterizedBeanPropertyRowMapper.newInstance(IDeviceGrant.class),
                new Object[] { map.get("appointId") });
    }

}
